package com.endbd.systemmanagement.service.area;

import com.endbd.feignapi.model.system.City;
import com.endbd.feignapi.model.system.Province;
import com.endbd.systemmanagement.dao.area.AreaDao;
import com.endbd.systemmanagement.model.AreaCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaServiceImpl implements AreaService{

  @Autowired
  private AreaDao areaDao;

  @Override
  public List<Province> getAreaList() {
    List<Province> areaList = areaDao.getAreaList();
    for(int i= areaList.size()-1;i>=0;i--){
      Province province = areaList.get(i);
      if(province.getCity().size()==1 && province.getCity().get(0).getId()==null) areaList.remove(i);
    }
    return areaList;
  }

  @Override
  public Province queryArea(AreaCondition areaCondition) {
    return areaDao.queryArea(areaCondition);
  }

  @Override
  public City queryCity(AreaCondition areaCondition) {
    return areaDao.queryAreaByCity(areaCondition);
  }
}
